package demo3;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: mac
 * Date: 2022-09-06
 * Time: 19:35
 */
class Animal {
    protected String name;

    public Animal(String name) {
        this.name = name;
    }
}
//不是所有的动物都会飞 - 所以不能写到animal当中，也不能写到其它的类，因为只能继承一个类
interface IFlying {
    void fly();
}
interface IRunning {
    void run();
}
interface ISwimming {
    void swim();
}
class Bird extends Animal implements IFlying{
    public Bird(String name) {
        super(name);
    }

    @Override
    public void fly() {
        System.out.println(this.name + "正在飞！");
    }
}
class Frog extends Animal implements IRunning,ISwimming{
    public Frog(String name) {
        super(name);
    }

    @Override
    public void run() {
        System.out.println(this.name + "正在跑");
    }

    @Override
    public void swim() {
        System.out.println(this.name + "正在游泳");
    }
}
class Duck extends Animal implements IRunning,ISwimming,IFlying{
    public Duck(String name) {
        super(name);
    }

    @Override
    public void fly() {
        System.out.println(this.name + "正在飞！");
    }

    @Override
    public void run() {
        System.out.println(this.name + "正在跑");
    }

    @Override
    public void swim() {
        System.out.println(this.name + "正在游泳");
    }
}
class Roobot implements IRunning{
    @Override
    public void run() {
        System.out.println("机器人在跑");
    }
}
public class Test4 {
    public static void runFunc(IRunning iRunning) {
        iRunning.run();
    }
    public static void swimmingFunc(ISwimming iSwimming){
        iSwimming.swim();
    }
    public static void flyingFunc(IFlying iFlying){
        iFlying.fly();
    }

    public static void main3(String[] args) {
        flyingFunc(new Bird("小鸟"));
        flyingFunc(new Duck("鸭子"));
    }
    public static void main2(String[] args) {
        swimmingFunc(new Duck("鸭子"));
        swimmingFunc(new Frog("青蛙"));
    }
    public static void main(String[] args) {
        runFunc(new Roobot());
        runFunc(new Duck("鸭子"));
        runFunc(new Frog("青蛙"));
    }
}
